<template>
    <div class="header">
        <div class="header-title">
            <div class="left-item">
                <button @click="onTabChange(item,index)" class="tab-btn" v-for="(item,index) in tabList" :key="index">
                    <span>{{item.name}}</span>
                    <img :src="currentTabIndex==index?activeTabIcon:defaultTabIcon" alt="">
                </button>
                <div class="date-row">
                    <img src="../../assets/dp2/dj-date-title.png" alt="">
                    <div class="date-row-wrapper">
                        <span class="date">{{nowDate.date}}</span>
                        <span class="week">{{nowDate.weekDay}}</span>
                    </div>
                </div>
            </div>
            <div class="middle-item">
                <div class="time-wrapper">
                    <div class="time-row">{{nowDate.hours}}
                        <div class="left-top"></div>
                        <div class="left-bottom"></div>
                        <div class="right-top"></div>
                        <div class="right-bottom"></div>
                    </div>
                    <span> : </span>
                    <div class="time-row">{{nowDate.minutes}}
                        <div class="left-top"></div>
                        <div class="left-bottom"></div>
                        <div class="right-top"></div>
                        <div class="right-bottom"></div>
                    </div>
                    <span> : </span>
                    <div class="time-row">{{nowDate.seconds}}
                        <div class="left-top"></div>
                        <div class="left-bottom"></div>
                        <div class="right-top"></div>
                        <div class="right-bottom"></div>
                    </div>
                </div>
                <div  class="logo-wrppaer">
                    <img @click = "()=>{this.$router.push('/welcome');}"  src="../../assets/dp2/dj-logo.png" alt="">
                </div>
                <div class="weather-wrapper">
                    <!-- <img class="weather-img" :src="weatherInfo.weatherImg" alt="">
                    <div>
                        <span class="weather-num">{{weatherInfo.temp}}</span>
                        <span class="weather-tag">℃</span>
                    </div>
                    <div class="weather-value">
                        <div class="weather-status">{{weatherInfo.weather}}</div>
                        <div>{{weatherInfo.tempRange}}</div>
                    </div> -->
                    <img class="site-img" src="../../assets/layout/local-site.png" alt="">
                    <div class="site-name">肥乡区</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
let defaultTabIcon = require("../../assets/dp2/dj-default-icon.png");
let activeTabIcon = require("../../assets/dp2/dj-active-icon.png");
const weather1 = require("../../assets/dp1/weather1.png");
import Pubsub from "../../utils/pubsub";
import { getWeather } from "../../config/api";
export default {
    props: ["nowDate"],
    data() {
        return {
            tabList: [
                { name: "累积", type: "" },
                { name: "当年", type: "year" },
                { name: "当月", type: "month" },
                { name: "当日", type: "today" }
            ],
            activeTabIcon,
            defaultTabIcon,
            currentTabIndex: "0", //当前选中tab下标
            weatherInfo: {
                temp: 0,
                weatherImg: weather1,
                tempRange: "",
                weather: ""
            }
        };
    },
    mounted() {
        this.getWeather();
        this.timer1 = setInterval(this.getWeather, 1000 * 60 * 30);
    },
    destroyed() {
        this.timer1 && clearInterval(this.timer1);
    },
    methods: {
        /**
         * 获取天气
         */
        getWeather() {
            getWeather().then((result = {}) => {
                this.weatherInfo = result.data || {};
            });
        },
        /**
         * tab切换
         */
        onTabChange(item, index) {
            this.currentTabIndex = index;
            Pubsub.publish("refreshDp2Data", { type: item.type });
        }
    }
};
</script>

<style lang="scss" scoped>
.header {
    position: absolute;
    height: 110px;
    width: 3072px;
    background: url("../../assets/dp2/dj-header-bg.png") no-repeat;
    background-size: 100% 100%;
}
.header-title {
    height: 110px;
    display: flex;
    position: relative;
    padding-bottom: 14px;
    box-sizing: border-box;
    align-items: flex-end;
    .tab-btn {
        position: relative;
        margin-right: 10px;
        z-index: 999;
        span {
            color: #fff;
            position: absolute;
            left: 34px;
            top: 8px;
        }
    }
    .date-row {
        margin-left: 22px;
        margin-bottom: 14px;
        position: relative;
        font-family: "Regular";

        .date-row-wrapper {
            height: 36px;
            width: 303px;
            position: absolute;
            bottom: 3px;
            right: 14px;
            display: flex;
            align-items: center;
            font-size: 24px;
            .date {
                margin-left: 40px;
                margin-right: 50px;
            }
            .week{
                font-family: "SSZHJT";
                font-size: 20px;
            }
        }
    }
}
.left-item {
    width: 936px;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    padding-left: 13px;
}
.middle-item {
    width: 1200px;
    height: 110px;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    .weather-wrapper {
        width: 240px;
        height: 56px;
        font-size: 28px;
        // border: 1px solid #fff;
        display: flex;
        align-items: flex-end;
        justify-content: center;
        .site-img{
            height:42px;
            width: 42px;
            margin-bottom:4px;
            margin-right: 10px;

        }
      
        .weather-img {
            height: 56px;
        }
        .weather-num {
            font-size: 32px;
            margin-left: 15px;
            margin-right: 3px;
        }
        .weather-tag {
            font-size: 18px;
        }
        .weather-value {
            font-size: 18px;
            margin-left: 25px;
        }
        .weather-status {
            text-align: center;
        }
    }
    .time-wrapper {
        font-family: "Regular";
        display: flex;
        align-items: center;
        font-size: 24px;
        color: #fff100;
        text-align: center;
        margin-top: 5px;
        width: 240px;
        box-sizing: border-box;
        padding-left: 40px;
    }
    .time-row {
        box-sizing: border-box;
        position: relative;
        width: 40px;
        height: 40px;
        background-color: rgba(195, 5, 5, 0.4);
        border: solid 1px #9b5153;
        margin: 0 8px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .left-top {
        height: 6px;
        width: 6px;
        border-top: 1px solid #ff9d9d;
        border-left: 1px solid #ff9d9d;
        left: -1px;
        position: absolute;
        top: -1px;
        opacity: 0.6;
    }
    .left-bottom {
        height: 6px;
        width: 6px;
        border-bottom: 1px solid #ff9d9d;
        border-left: 1px solid #ff9d9d;
        left: -1px;
        position: absolute;
        bottom: -1px;
        opacity: 0.6;
    }
    .right-top {
        height: 6px;
        width: 6px;
        border-top: 1px solid #ff9d9d;
        border-right: 1px solid #ff9d9d;
        right: -1px;
        position: absolute;
        top: -1px;
        opacity: 0.6;
    }
    .right-bottom {
        height: 6px;
        width: 6px;
        border-right: 1px solid #ff9d9d;
        border-bottom: 1px solid #ff9d9d;
        right: -1px;
        position: absolute;
        bottom: -1px;
        opacity: 0.6;
    }
    .logo-wrppaer {
        flex: 1;
        display: flex;
        justify-content: center;
        cursor: pointer;
        z-index: 9999;
    }
}
</style>